#include "../mqserver/mq_queue.hpp"
#include <gtest/gtest.h>

qqmq::MsgQueueManager::ptr qmp;

class QueueTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        qmp = std::make_shared<qqmq::MsgQueueManager>("./data/meta.db");
    }
    virtual void TearDown() override
    {
        // qmp->clear();
    }
};

TEST(queue_test, insert_test)
{
    // std::unordered_map<std::string, std::string> map{{"123", "456"}};
    google::protobuf::Map<std::string, std::string> map;
    map.insert({"123", "456"});
    qmp->declareQueue("queue1", true, false, false, map);
    qmp->declareQueue("queue2", true, false, false, map);
    qmp->declareQueue("queue3", true, false, false, map);
    qmp->declareQueue("queue4", true, false, false, map);
    ASSERT_EQ(qmp->size(), 4);
}

TEST(queue_test, select_test)
{
    // ASSERT_EQ(qmp->exists("queue1"), false);
    // ASSERT_EQ(qmp->exists("queue2"), false);
    ASSERT_EQ(qmp->exists("queue3"), true);
    ASSERT_EQ(qmp->exists("queue4"), true);

    qqmq::MsgQueue::ptr mqmp = qmp->selectQueue("queue3");
    ASSERT_NE(mqmp.get(), nullptr);
    ASSERT_EQ(mqmp->name, "queue3");
    ASSERT_EQ(mqmp->durable, true);
    ASSERT_EQ(mqmp->exclusive, false);
    ASSERT_EQ(mqmp->auto_delete, false);
    ASSERT_EQ(mqmp->getArgs(), std::string("123=456&"));
}

TEST(queue_test, remove_test)
{
    qmp->deleteQueue("queue3");
    ASSERT_EQ(qmp->exists("queue3"), false);
}

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new QueueTest);
    return RUN_ALL_TESTS();
}